﻿using System;
using System.Collections.Generic;
using System.Text;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Events.Bus.Entities;
using Abp.Events.Bus.Handlers;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.Comm;
using FwProject.Core.Car;
using FwProject.Core.Restaurant;

namespace FwProject.Application.EventHandle
{
    public class LoadCarHandle : IEventHandler<EntityChangedEventData<LoadCar>>, ITransientDependency
    {
        private readonly IRepository<CarInfo, Guid> _repositoryCarInfo;
        public readonly ICacheManager _catchmanager;
        public IRemoteEventBus remoteEventBus { get; set; }//缓存对象
        public LoadCarHandle(ICacheManager catchmanager, IRepository<CarInfo, Guid> repositoryCarInfo)
        {
            _catchmanager = catchmanager;
            _repositoryCarInfo = repositoryCarInfo;
            remoteEventBus = NullRemoteEventBus.Instance;
        }
        [UnitOfWork]
        public void HandleEvent(EntityChangedEventData<LoadCar> eventData)
        {
            ICache cache = _catchmanager.GetCache(nameof(LoadCar));
            cache.Remove("list");

            ///装车通知
            var eventDate = new RemoteEventData(RemoteTypeHelp.TypeLoadCarPushMessage)
            {
                Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.Id }
            };
            remoteEventBus.Publish(RemoteTypeHelp.TopicLoadCar, eventDate);

            ///缓存修改
            var catcheventDate = new RemoteEventData(RemoteTypeHelp.TypeModelCatch)
            {
                Data = { [RemoteTypeHelp.Model] = nameof(LoadCar) }
            };
            remoteEventBus.Publish(RemoteTypeHelp.TopicSystemCatch, catcheventDate);





        }
    }
}
